package jmine.tec.web.wicket.cronExpression;

import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;

/**
 * Component that build fields referent to the strategy passed on it's constructor.
 * 
 * @author Fabio Sakiyama
 * @created 08/11/2011
 */
public class CronExpressionComponent extends Panel {

    private CronExpressionTypeStrategy strategy;

    private String cronExpression;

    /**
     * C'tor
     * 
     * @param id wicket id of the component
     * @param strategy {@link CronExpressionTypeStrategy}
     * @param iModel model to set the cron expression.
     * @param excludeFields optional fields ({@link OptionalComponentsEnum}) that can be excluded from the page.
     */
    public CronExpressionComponent(String id, CronExpressionTypeStrategy strategy, IModel<String> iModel,
            OptionalComponentsEnum... excludeFields) {
        super(id, iModel);
        this.strategy = strategy;
        this.add(strategy.buildScreenFields(iModel, excludeFields));
    }

    /**
     * @return the cronExpression
     */
    public String getCronExpression() {
        return this.cronExpression;
    }

    /**
     * @param cronExpression the cronExpression to set
     */
    public void setCronExpression(String cronExpression) {
        this.cronExpression = cronExpression;
        this.strategy.populateScreenFields(cronExpression);
    }

}
